package cst.a220tbc.recyclertestdata_220tbc;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import java.util.List;

import cst.a220tbc.recyclertestdata_220tbc.adapter.MyAdapter;
import cst.a220tbc.recyclertestdata_220tbc.bean.ArticleBean;
import cst.a220tbc.recyclertestdata_220tbc.iface.ArticleListener;
import cst.a220tbc.recyclertestdata_220tbc.model.ArticleModel;

public class MainActivity extends AppCompatActivity  implements ArticleListener {
    private RecyclerView recyclerView;
    private MyAdapter mAdapter;
    List<ArticleBean> list;
    private RecyclerView.LayoutManager layoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }
    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclervView1);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //    list = getData();
        mAdapter = new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);

    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list = list;
        mAdapter.setList(list);
        mAdapter.notifyDataSetChanged();//通知数据改变

    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this,"fail:"+msg,Toast.LENGTH_SHORT).show();

    }
    public void setLayoutManager(RecyclerView.LayoutManager layoutManager) {
        this.layoutManager = layoutManager;
    }

}
